<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php /* @var $this \Magento\Downloadable\Block\Adminhtml\Catalog\Product\Composite\Fieldset\Downloadable */ ?>
<?php $_linksPurchasedSeparately = $this->getLinksPurchasedSeparately(); ?>
<?php $_skipSaleableCheck = $this->helper('Magento\Catalog\Helper\Product')->getSkipSaleableCheck(); ?>
<?php if (($this->getProduct()->isSaleable() || $_skipSaleableCheck) && $this->hasLinks()):?>

<fieldset id="catalog_product_composite_configure_fields_downloadable" class="fieldset downloadable information<?php echo $this->getIsLastFieldset() ? ' last-fieldset' : '' ?>">
    <legend class="legend"><span><?php echo __('Downloadable Information') ?></span></legend><br />
    <?php $_links = $this->getLinks(); ?>
    <?php $_isRequired = $this->getLinkSelectionRequired(); ?>
    <div class="field link<?php if ($_isRequired) echo ' required' ?>">
        <label class="label"><span><?php echo $this->getLinksTitle() ?></span></label>
        <div class="control" id="downloadable-links-list">
            <?php foreach ($_links as $_link): ?>
                <div class="nested">
                <?php if ($_linksPurchasedSeparately): ?>
                    <input type="checkbox" class="checkbox<?php if ($_isRequired):?> validate-one-required-by-name<?php endif; ?> product downloadable link" name="links[]" id="links_<?php echo $_link->getId() ?>" value="<?php echo $_link->getId(); ?>" <?php echo $this->getLinkCheckedValue($_link); ?> price="<?php echo $this->getCurrencyPrice($_link->getPrice()); ?>"/>
                    <?php endif; ?>
                    <label for="links_<?php echo $_link->getId() ?>" class="label">
                    <?php echo $this->escapeHtml($_link->getTitle()) ?>
                    <?php if ($_link->getSampleFile() || $_link->getSampleUrl()): ?>
                        &nbsp;(<a href="<?php echo $this->getLinkSampleUrl($_link) ?>" <?php echo $this->getIsOpenInNewWindow()?'onclick="this.target=\'_blank\'"':''; ?>><?php echo __('sample') ?></a>)
                    <?php endif; ?>
                    <?php if ($_linksPurchasedSeparately): ?>
                    <?php echo $this->getFormattedLinkPrice($_link); ?>
                        <br />
                        <?php echo $this->getLinkPrice($_link); ?>
                    <?php endif; ?>
                    </label>
                <?php if ($_isRequired): ?>
                    <script type="text/javascript">
require(['prototype'], function(){

    //<![CDATA[
    $('links_<?php echo $_link->getId() ?>').advaiceContainer = 'links-advice-container';
    $('links_<?php echo $_link->getId() ?>').callbackFunction = 'validateDownloadableCallback';
    //]]>
                    
});
</script>
                <?php endif; ?>
            </div>
            <?php endforeach; ?>
        <?php if ($_isRequired): ?>
            <span id="links-advice-container"></span>
        <?php endif;?>
        </div>
    </div>
</fieldset>

    <script type="text/javascript">
require(['prototype'], function(){

//<![CDATA[
    validateDownloadableCallback = function (elmId, result) {
        var container = $('downloadable-links-list');
        if (result == 'failed') {
            container.removeClassName('validation-passed');
            container.addClassName('validation-failed');
        } else {
            container.removeClassName('validation-failed');
            container.addClassName('validation-passed');
        }
    }
//]]>
    
});
</script>
<?php endif;?>
